package com.jsyh.maidu.presenter;

import android.content.Context;

import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.http.BaseDelegate;
import com.jsyh.maidu.http.ExceptionHelper;
import com.jsyh.maidu.http.OkHttpClientManager;
import com.jsyh.maidu.model.HomePageModel;
import com.jsyh.maidu.utils.Utils;
import com.jsyh.maidu.views.HomePageView;
import com.squareup.okhttp.Request;

/**
 * Created by ZHY_9 on 2017/6/16.
 */

public class HomePagePresenter extends BasePresenter {

    private HomePageView homePageView;

    public HomePagePresenter(HomePageView homePageView) {
        this.homePageView = homePageView;
    }

    public void getHomePageData(final Context context){
        initLoadDialog(context);
        mLoadingDialog.show();
        OkHttpClientManager.getAsyn(context, ConfigValue.APP_IP + "first/index", new BaseDelegate.ResultCallback<HomePageModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                mLoadingDialog.dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(HomePageModel response, Object tag) {
                mLoadingDialog.dismiss();
                homePageView.getData(response);
            }
        });
    }
}
